<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<!doctype html>
<html>
<head>
<title>投注来源配置</title>
<%@ include file="../../common/base.jsp" %>
</head>

<body id="body">
<!--head-->
<div id="head">
	<%@ include file="../../common/head.jsp" %>
</div>
<!--head end-->
<!--container-->
<div id="container">
	<div id="pageId" style="display: none;">05-04</div>
		<!--sidebar-->
		<%@ include file="../../common/menu.jsp" %>
	    <!--sidebar-->
    <!--main-->
    <div class="main">
    	<div class="location" style="background-position:22px -149px;">
        	系统配置<span>&gt;</span>投注来源配置
        </div>
        <!--content-->
        <div class="content">
        <div class="set_buttons">
            <button type="button" class="btn btn_add" onClick="showAddPage()">添加</button>
        </div>
            <div id="tableResult">
            	<table class="table_type1">
	                <thead>
	                    <tr>
	                        <th>序号</th>
	                        <th>投注来源名称</th>
	                        <th>投注来源编码</th>
	                        <th>操作</th>
	                    </tr>
	                </thead>
	                <tbody id="bodyResult"></tbody>
	            </table>
            </div>
            <div class="page">
                	<div class="itemNum" >
		                    	显示：<select id="selItem">
		                    			<option selected="selected" id="20">20</option>
		                    			<option id="30">30</option>
		                    			<option id="40">40</option>
		                    			<option id="50">50</option>
		                    		</select>条，共 <a id="totalCount" onClick="javascript:void(0);" ></a> 条
		                    </div>
                    <ul class="pagination" id="pageCur"></ul>
                </div>
        </div>
        <!--content-->
        <!--foot-->
        <div id="foot">
        	<p>北京掌中彩信息科技有限公司  提供技术支持</p>
        </div>
        <!--foot-->
    </div>
    <!--main-->
</div>
<!--遮罩层-->
<div id="mask" style="display:none;"></div>
<!--遮罩层-->
<!--弹出框-->
<div id="popBox" style="width:400px; margin-left:-200px;display:none;">
	<h2>添加</h2>
    <a href="javascript:;" class="close" onClick="$(this).parent('#popBox').hide(); $('#mask').hide()"></a>
    <div class="pop_content">
      <ul class="inputInfoList3">
        <li>
          <label>投注来源编码</label>
          <input type="text" onFocus="this.style.border = '1px solid #2A7CCF'"  class="text" id="enumCodeAdd" onBlur="exitOrNot('11','11','ecode');this.style.border = '1px solid #D5D5D5'" maxlength="2"></input>
          <span class="red">*</span>
          <p id="enumCodeAddTip" style="display: none; padding-left: 125px; text-align:left;"></p>
        </li>
        <li>
          <label>投注来源名称</label>
          <input type="text" onFocus="this.style.border = '1px solid #2A7CCF'"  class="text" id="enumNameAdd" onBlur="exitOrNot('11','12','ename');this.style.border = '1px solid #D5D5D5'" maxlength="20"></input>
          <span class="red">*</span>
          <p id="enumNameAddTip" style="display: none; padding-left: 125px; text-align:left;"></p>
        </li>
      </ul>
    </div>
    <div class="pop_button">
    	<a href="javascript:submitForm('11');">添加</a>
    </div>
</div>
<!--弹出框-->
<div id="popBox" style="width:400px; margin-left:-200px;display:none;" class="popBoxModify">
	<h2>修改</h2>
    <a href="javascript:;" class="close" onClick="$(this).parent('#popBox').hide(); $('#mask').hide()"></a>
    <div class="pop_content">
      <ul class="inputInfoList3">
        <li>
          <label>投注来源编码</label>
          <input type="text" onFocus="this.style.border = '1px solid #2A7CCF'" onBlur="this.style.border = '1px solid #D5D5D5'"  class="text" id="enumCodeModify" value=""  disabled="disabled"></input>
          <span class="red">*</span>
        </li>
        <li>
          <label>投注来源名称</label>
          <input type="text" onFocus="this.style.border = '1px solid #2A7CCF'"  class="text" id="enumNameModify" value="" onBlur="exitOrNot('12','11','ename');this.style.border = '1px solid #D5D5D5'" maxlength="20"></input>
          <span class="red">*</span>
          <p id="enumNameModifyTip" style="display: none; padding-left: 125px; text-align:left;"></p>
        </li>
      </ul>
    </div>
    <div class="pop_button">
    	<a href="javascript:submitForm('12');">修改</a>
    </div>
</div>
<!--container-->
<script src="${pageContext.request.contextPath}/static/js/basic.js"></script>
<script type="text/javascript">
//加载ajax请求
function loadResult(page,numPerPage){
	loadResultPerfect(page,numPerPage,"bettingResourceConfig/queryBettingResourceList","");
}
// 加载ajax返回结果
function loadTableResult(data){
	var jo = data.json;
	if(jo != '' && jo != null){
		for (var i = 0; i < jo.length; i++) {
			var enumName = jo[i].enumName.toString();
			var enumCode = jo[i].enumCode;
			var content = "<tr>"+
	                    	"<td>"+(i+1)+"</td><td>"+jo[i].enumName+
	                    	"</td><td>"+jo[i].enumCode+
	                    	"</td><td><a href='javascript:showModifyPage(\""+enumCode+"\",\""+enumName+"\");'>修改</a></td>"+
	                      "</tr>";
	        $("#bodyResult").append(content);
	    }
	}
}

function del(operatorId){
	prompt.confirm("您确定要删除吗?",function(){
			$.ajax({
			   type: "POST",
			   url: "${pageContext.request.contextPath}/operatorManagement/deleteOperator",
			   dataType:"json",
			   data: {
				   operatorId:operatorId
			   },
			   success: function(data){
			   		prompt.alert(data.msg);
					if (data.errorCode==0) {
						loadResult(1,$("#selItem").val());
					}
			   }
		});	
	});
}
function resetPwd(operatorId){
	prompt.confirm("您确定要重置密码吗?",function(){
			$.ajax({
			   type: "POST",
			   url: "${pageContext.request.contextPath}/operatorManagement/resetPwd",
			   dataType:"json",
			   data: {
				   operatorId:operatorId
			   },
			   success: function(data){
			   		prompt.alert(data.msg);
					if (data.errorCode==0) {
						loadResult(1,$("#selItem").val());
					}
			   }
		});	
	});
}
function showAddPage(){
	$("#mask").show();
	$("#popBox").show();
}
function showModifyPage(enumCode,enumName){
	$("#enumCodeModify").val(enumCode);
	$("#enumNameModify").val(enumName);
	$("#mask").show();
	$(".popBoxModify").show();
}
function submitForm(addOrModify){
	var check = /^\d{1,2}$/;
	var checkCharOrNum = /^[\u4E00-\u9FA5a-zA-Z]{2,20}$/;
	var enumCode = '';
	var enumName = '';
	var saveOrUpdate = '';
	if(addOrModify == '11'){
		enumCode = $("#enumCodeAdd").val();
		enumName = $("#enumNameAdd").val();
		if(!exitOrNot("11","11","ecode")){
			return;
		}
		if(!exitOrNot("11","12","ename")){
			return;
		}
		saveOrUpdate = 'save';
	}
	if(addOrModify == '12'){
		saveOrUpdate = 'update';
		enumCode = $("#enumCodeModify").val();
		enumName = $("#enumNameModify").val();
		if(!exitOrNot("12","11","ename")){
			return;
		}
	}
	
	
	$.ajax({
		   type: "POST",
		   url: "${pageContext.request.contextPath}/bettingResourceConfig/saveOrUpdateBettingResource?type="+saveOrUpdate+"&bettingResource.enumCode="+enumCode+"&bettingResource.enumName="+enumName,
		   dataType:"json",
		   data: {
			   enumCode:enumCode,
			   enumName:enumName
		   },
		   success: function(data){
			   prompt.alert(data.msg);
			   $("#mask").hide();
			   $("#popBox").hide();
			   $(".popBoxModify").hide();
			   location.reload();
		   },
		   error: function(){
			   $("#mask").show();
			   $("#popBox").show();
				
			}
	});
}
function exitOrNot(addOrModify,codeOrName,focusFlag){
	var enumCode = '';
	var enumName = '';
	var saveOrUpdate = '';
	var check = /^\d{1,2}$/;
	var checkCharOrNum = /^[\u4E00-\u9FA5a-zA-Z]{2,20}$/;
	if(addOrModify == '11'){
		
		enumCode = $("#enumCodeAdd").val();
		enumName = $("#enumNameAdd").val();
		if(codeOrName == '11' && focusFlag=='ecode'){
			$("#enumCodeAddTip").hide();
			$("#enumCodeAddTip").html("");
			saveOrUpdate = 'tzCode';
			if (enumCode=='') {
				//prompt.alert("投注来源编码不能为空");
				$("#enumCodeAddTip").append("投注来源编码不能为空");
				$("#enumCodeAddTip").show();
				$("#enumCodeAdd").focus();
				return;
			}else if(enumCode !='' && !check.test(enumCode)){
				//prompt.alert("输入错误,由1-2位数字组成！");
				$("#enumCodeAddTip").append("输入错误,由1-2位数字组成！");
				$("#enumCodeAddTip").show();
				$("#enumCodeAdd").focus();
				return;
			}
		}else if(codeOrName == '12'&& focusFlag=='ename'){
			$("#enumNameAddTip").hide();
			$("#enumNameAddTip").html("");
			saveOrUpdate = 'tzName';
			if (enumName=='') {
				//prompt.alert("投注来源名称不能为空");
				$("#enumNameAddTip").append("投注来源名称不能为空");
				$("#enumNameAddTip").show();
				$("#enumNameAdd").focus();
				return;
			}else if(enumName !='' && !checkCharOrNum.test(enumName)){
				//prompt.alert("输入错误，由2-20位字母或汉字组成！");
				$("#enumNameAddTip").append("输入错误，由2-20位字母或汉字组成！");
				$("#enumNameAddTip").show();
				$("#enumNameAdd").focus();
				return;
			}
		}
		
	}
	if(addOrModify == '12'){
		$("#enumNameModifyTip").hide();
		$("#enumNameModifyTip").html("");
		saveOrUpdate = 'tzName';
		enumCode = '';
		enumName = $("#enumNameModify").val();
		if (enumName=='') {
			//prompt.alert("投注来源名称不能为空");
			$("#enumNameModifyTip").append("投注来源名称不能为空");
			$("#enumNameModifyTip").show();
			$("#enumNameModify").focus();
			return;
		}else if(enumName !='' && !checkCharOrNum.test(enumName)){
			//prompt.alert("输入错误，由2-20位字母或汉字组成！");
			$("#enumNameModifyTip").append("输入错误，由2-20位字母或汉字组成！");
			$("#enumNameModifyTip").show();
			$("#enumNameModify").focus();
			return;
		}
	}
	
	
	$.ajax({
		   type: "POST",
		   url: "${pageContext.request.contextPath}/bettingResourceConfig/bettingExitOrNo?type="+saveOrUpdate+"&bettingResource.enumCode="+enumCode+"&bettingResource.enumName="+enumName,
		   dataType:"json",
		   data: {
			   enumCode:enumCode,
			   enumName:enumName
		   },
		   success: function(data){
			   if(data.errorCode == 1){
				  if(addOrModify == '11'){
					  if(codeOrName == '11' && focusFlag=='ecode'){
						   $("#enumCodeAddTip").hide();
						   $("#enumCodeAddTip").html("");
						   $("#enumCodeAddTip").append(data.msg);
						   $("#enumCodeAddTip").show();
						   $("#enumCodeAdd").focus();
					   }else if(codeOrName == '12'&& focusFlag=='ename'){
						   $("#enumNameAddTip").hide();
						   $("#enumNameAddTip").html("");
						   $("#enumNameAddTip").append(data.msg);
						   $("#enumNameAddTip").show();
						   $("#enumNameAdd").focus();
					   }
				  }
				  if(addOrModify == '12'){
						$("#enumNameModifyTip").hide();
						$("#enumNameModifyTip").html("");
						$("#enumNameModifyTip").append(data.msg);
						$("#enumNameModifyTip").show();
						$("#enumNameModify").focus();
					}
				   
				   //prompt.alert(data.msg);
				    
			   }
		   },
		   error: function(){
			   $("#mask").show();
			   $("#popBox").show();
				
			}
	});
	return true;
}

//表格排序表头样式
$(document).ready(function(e) {
	loadResult(1,$("#selItem").val());
});

</script>
</body>
</html>